/**
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var search = function (nums, target) {
	// 判空
	if (!nums) {
		return -1;
	}
	// 左右指针查找左右边界
	let left = 0, right = nums.length - 1;
	// 左边界
	while (nums[left] !== target && left <= right) {
		left++;
	}
	// 右边界
	while (nums[right] !== target && right >= 0) {
		right--;
	}
	return left <= right ? right - left + 1 : 0;
};
let nums = [5, 7, 7, 8, 8, 10], target = 8;
console.log(search(nums, target))